package com.ruoyi.ams.util;

import java.util.List;

public class ListFormUtils {

    public static List getPageList(List list, int currentPage, int maxNum, int pageNum) {
        int totalCount = list.size();
        int pageCount;
        int m = totalCount % maxNum;

        if (m > 0) {
            pageCount = totalCount / maxNum + 1;
        } else {
            pageCount = totalCount / maxNum;
        }


        int fromIndex = 0; // 从哪里开始截取
        int toIndex = 0; // 截取几个
        if (list == null || list.size() == 0)
            return null;
        // 当前页小于或等于总页数时执行
        if (currentPage <= pageCount && currentPage != 0) {
            fromIndex = (currentPage - 1) * maxNum;

            if (currentPage == pageCount) {
                toIndex = list.size();

            } else {
                toIndex = currentPage * maxNum;
            }

        }
        return list.subList(fromIndex, toIndex);
    }

}
